using Light;
using Light.Assets.Scripts.EventManager;
using UnityEngine;
using UnityEngine.UI;

namespace Dream.FirstLevel.UI
{
    public class ScoreController : MonoBehaviour
    {
        [SerializeField] private Text scoreTextUI;


        private int Score;

        private void Awake()
        {
            EventManager.Register<ProductResultEvent>(OnProductResultEventHandle);
        }

        private void OnDestroy()
        {
            EventManager.Unregister<ProductResultEvent>(OnProductResultEventHandle);
        }

        private void OnProductResultEventHandle(ProductResultEvent obj)
        {
            if (obj.isComplated)
                Score += obj.pointsChange;
            else
                Score -= obj.pointsChange;

            scoreTextUI.text = "KPI：" + Score;
        }
    }
}